package com.example.demo.service.Impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.entity.Game;
import com.example.demo.mapper.GameMapper;
import com.example.demo.service.GameService;
import com.example.demo.util.GameAnswerUtil;
import org.springframework.stereotype.Service;
import static com.example.demo.util.Constants.*;

@Service
public class GameServiceImpl extends ServiceImpl<GameMapper, Game> implements GameService {

    /**
     * @return String
     * @description 创建游戏题目
     */
    @Override
    public long[] createGame() {
        long[] heightList;
        heightList = new long[GAME_AMOUNT];
        for (int i = 0;i < GAME_AMOUNT;i++) {
            heightList[i] = (long) (Math.random() * 100 + 1);
        }
        return heightList;
    }

    @Override
    public long answerGame(long[] heightList) {
        return GameAnswerUtil.computeAnswer(heightList);
    }
}
